/*
 * To change this template, choose Utils | Templates
 * and open the template in the editor.
 */
package customers;

import avenue.MyWindowEvent;
import avenue.Utils;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JOptionPane;
import model.Card;
import model.DBManager;
import model.Program;
import model.Vehicle;
import model.VehicleCategory;
import model.VehicleModel;

public class VehicleDialog extends javax.swing.JFrame {

    /**
     * Creates new form VehicleDialog
     */
    public VehicleDialog(Vehicle v) {
        // super(parent, modal);
        avenuePUEntityManager = DBManager.em;
        vehicle1 = v;

        initComponents();

        Utils.centerOnScreen(this);
        Utils.logUCstart(this);
        if (v.getId() != null) {
            jTxtRegNumber.setText(v.getRegNumber());
            jTxtRegNumber.setEditable(false);
            jTxtCard.setText(String.format("%d", v.getCardId().getBarcode()));
            jTxtCard.setEditable(false);
            jCmbProgram.setEnabled(false);

            jCmbCategory.setEnabled(false);
            jCmbModel.setEnabled(false);
            if (v.getCardId().getActive() == 1) {
                jChActive.setSelected(true);
            }

        } else {
            jTxtRegNumber.requestFocus();
            //  ΔΗΜΙΟΥΡΓΟΥΜΕ ΕΝΑ EVENT ΓΙΑ ΝΑ ΕΛΕΓΧΟΥΜΕ ΠΟΤΕ ΑΛΛΕΖΕΙ Η ΕΠΙΛΟΓΗ ΣΤΟ 1ο COMBOBOX ΩΣΤΕ ΝΑ ΦΟΡΤΩΝΟΥΜΕ ΤΙΜΕΣ ΣΤΟ 2ο
            jCmbCategory.addItemListener(new ItemListener() {
                public void itemStateChanged(ItemEvent e) {

                    if (e.getStateChange() == ItemEvent.SELECTED) {

                        vehicleModelQuery = avenuePUEntityManager.createQuery("SELECT v FROM VehicleModel v where v.categoryId=:categoryId").setParameter("categoryId", (VehicleCategory) jCmbCategory.getSelectedItem());
                        vehicleModelList.clear();
                        vehicleModelList.addAll(vehicleModelQuery.getResultList());
                        vehicle1.setModelId(((VehicleModel) vehicleModelList.get(0)));
                        jCmbModel.setSelectedItem(vehicle1.getModelId());
                    }
                }
            });
        }

        /*chColor.select(vehicle1.getColourId());*/
        checkControls();
    }

    private void checkControls() {
        if (vehicle1.getId() != null) {
            jBtnSave.setEnabled(true);
        } else if (jTxtRegNumber.getText().trim().equals("")
                || jTxtCard.getText().trim().equals("")
                || (jCmbModel.getSelectedIndex() == -1)
                || (jCmbCategory.getSelectedIndex() == -1)
                || (jCmbProgram.getSelectedIndex() == -1)) {
            jBtnSave.setEnabled(false);
        } else {
            jBtnSave.setEnabled(true);
        }

        if (jCmbCategory.isEnabled()) {
            jCmbModel.setEnabled(jCmbCategory.getSelectedIndex() != -1);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        model.Vehicle vehicle2 = vehicle1;
        vehicleCategoryQuery = java.beans.Beans.isDesignTime() ? null : avenuePUEntityManager.createQuery("SELECT v FROM VehicleCategory v");
        vehicleCategoryList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(vehicleCategoryQuery.getResultList());
        categoryBoxRenderer1 = new avenue.CategoryBoxRenderer();
        modelBoxRenderer1 = new avenue.ModelBoxRenderer();
        vehicleModelQuery = java.beans.Beans.isDesignTime() ? null : avenuePUEntityManager.createQuery("SELECT v FROM VehicleModel v");
        vehicleModelList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : vehicleModelQuery.getResultList();
        programQuery = java.beans.Beans.isDesignTime() ? null : avenuePUEntityManager.createQuery("SELECT p FROM Program p");
        programList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(programQuery.getResultList());
        programBoxRenderer2 = new avenue.ProgramBoxRenderer();
        vehicleColoursQuery1 = java.beans.Beans.isDesignTime() ? null : avenuePUEntityManager.createQuery("SELECT c FROM VehicleColour c");
        vehicleColourList1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : vehicleColoursQuery1.getResultList();
        colourRenderer1 = new avenue.ColourRenderer();
        jCmbCategory = new javax.swing.JComboBox();
        jBtnSave = new javax.swing.JButton();
        jBtnCancel = new javax.swing.JButton();
        jTxtRegNumber = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jTxtLName = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTxtFName = new javax.swing.JTextField();
        jTxtCard = new javax.swing.JTextField();
        jCmbModel = new javax.swing.JComboBox();
        jCmbProgram = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        chColor = new javax.swing.JComboBox();
        jChActive = new javax.swing.JCheckBox();

        categoryBoxRenderer1.setText("categoryBoxRenderer1");

        modelBoxRenderer1.setText("modelBoxRenderer1");

        programBoxRenderer2.setText("programBoxRenderer2");

        colourRenderer1.setText("colourRenderer1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Διαχείριση Οχήματος");
        setResizable(false);

        jCmbCategory.setRenderer(categoryBoxRenderer1);

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicleCategoryList, jCmbCategory);
        bindingGroup.addBinding(jComboBoxBinding);
        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicle2, org.jdesktop.beansbinding.ELProperty.create("${categoryId}"), jCmbCategory, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        jCmbCategory.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCmbCategoryActionPerformed(evt);
            }
        });

        jBtnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.gif"))); // NOI18N
        jBtnSave.setText("Αποθήκευση");
        jBtnSave.setEnabled(false);
        jBtnSave.setFocusable(false);
        jBtnSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBtnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnSaveActionPerformed(evt);
            }
        });

        jBtnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cancel.gif"))); // NOI18N
        jBtnCancel.setText("Ακυρο");
        jBtnCancel.setFocusable(false);
        jBtnCancel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBtnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnCancelActionPerformed(evt);
            }
        });

        jTxtRegNumber.setBackground(new java.awt.Color(227, 227, 227));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicle2, org.jdesktop.beansbinding.ELProperty.create("${regNumber}"), jTxtRegNumber, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jTxtRegNumber.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTxtRegNumberKeyTyped(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Αρ. Πινακίδας:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Κατηγορία:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Αρ. Συσκευής:");

        jLabel5.setText("Χρώμα:");

        jLabel7.setText("Μοντέλο:");

        jTxtLName.setEditable(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicle2, org.jdesktop.beansbinding.ELProperty.create("${custId.LName}"), jTxtLName, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jLabel8.setText("Κάτοχος:");

        jTxtFName.setEditable(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicle2, org.jdesktop.beansbinding.ELProperty.create("${custId.FName}"), jTxtFName, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jTxtCard.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTxtCardKeyTyped(evt);
            }
        });

        jCmbModel.setRenderer(modelBoxRenderer1);

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicleModelList, jCmbModel, "");
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicle2, org.jdesktop.beansbinding.ELProperty.create("${modelId}"), jCmbModel, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        jCmbModel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCmbModelActionPerformed(evt);
            }
        });

        jCmbProgram.setRenderer(programBoxRenderer2);

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, programList, jCmbProgram);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicle2, org.jdesktop.beansbinding.ELProperty.create("${cardId.programId}"), jCmbProgram, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        jLabel4.setText("Πρόγραμμα:");

        chColor.setRenderer(colourRenderer1);

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicleColourList1, chColor);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, vehicle2, org.jdesktop.beansbinding.ELProperty.create("${colourId}"), chColor, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        jChActive.setText("Ενεργή");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jBtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBtnSave))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel4))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTxtRegNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jTxtCard, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jChActive))
                            .addComponent(jCmbModel, 0, 189, Short.MAX_VALUE)
                            .addComponent(jCmbCategory, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTxtFName)
                            .addComponent(jTxtLName)
                            .addComponent(jCmbProgram, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(chColor, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(27, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTxtRegNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTxtLName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTxtFName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jCmbCategory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jCmbModel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(chColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTxtCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jChActive))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCmbProgram, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jBtnCancel)
                    .addComponent(jBtnSave))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jCmbCategory, jCmbModel});

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void closeMe(boolean exitAndSave) {
        MyWindowEvent we = new MyWindowEvent(this, WindowEvent.WINDOW_CLOSED, exitAndSave);
        for (WindowListener l : this.getWindowListeners()) {
            l.windowClosed(we);
        }
        this.setVisible(false);
    }

    private void jBtnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnSaveActionPerformed
        if (!Utils.acceptNumbersOnly(jTxtCard.getText())) {
            return;
        }

        if (vehicle1.getId() == null) {
            if (Utils.VehicleByRegNumber(jTxtRegNumber.getText()) != null) {
                Utils.showMessage(this, String.format(Utils.msgVehicleExists, jTxtRegNumber.getText()), Utils.msgDialogTitle, JOptionPane.WARNING_MESSAGE);
            } else if (Utils.VehicleByCardBarCode(jTxtCard.getText()) != null) {
                Utils.showMessage(this, String.format(Utils.msgCardExists, jTxtCard.getText()), Utils.msgDialogTitle, JOptionPane.WARNING_MESSAGE);
            } else {
                Card cid = new Card();

                cid.setBarcode((Integer.parseInt(jTxtCard.getText())));
                cid.setProgramId((Program) jCmbProgram.getSelectedItem());
                cid.setBalance(0d);


                cid.setActive(Utils.boolToInt(jChActive.isSelected()));

                cid.setActive(1);
                DBManager.em.persist(cid);
                vehicle1.setCardId(cid);
                vehicle1.getCardId().setBalance(0d);
                /*vehicle1.setColour(chColor.getSelectedItem());*/
                closeMe(true);

            }
        } else {
            vehicle1.getCardId().setActive(Utils.boolToInt(jChActive.isSelected()));
            closeMe(true);
        }
    }//GEN-LAST:event_jBtnSaveActionPerformed
    private void jBtnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnCancelActionPerformed
        // TODO add your handling code here:
        closeMe(false);
    }//GEN-LAST:event_jBtnCancelActionPerformed

    private void jTxtRegNumberKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxtRegNumberKeyTyped
        checkControls();        // TODO add your handling code here:
    }//GEN-LAST:event_jTxtRegNumberKeyTyped

    private void jCmbCategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCmbCategoryActionPerformed



        checkControls();        // TODO add your handling code here:
    }//GEN-LAST:event_jCmbCategoryActionPerformed

    private void jCmbModelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCmbModelActionPerformed
        checkControls();        // TODO add your handling code here:
    }//GEN-LAST:event_jCmbModelActionPerformed

    private void jTxtCardKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxtCardKeyTyped
        checkControls();
        // TODO add your handling code here:
    }//GEN-LAST:event_jTxtCardKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;


                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VehicleDialog.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VehicleDialog.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VehicleDialog.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VehicleDialog.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                VehicleDialog dialog = new VehicleDialog(new Vehicle());
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private avenue.CategoryBoxRenderer categoryBoxRenderer1;
    private javax.swing.JComboBox chColor;
    private avenue.ColourRenderer colourRenderer1;
    private javax.swing.JButton jBtnCancel;
    private javax.swing.JButton jBtnSave;
    private javax.swing.JCheckBox jChActive;
    private javax.swing.JComboBox jCmbCategory;
    private javax.swing.JComboBox jCmbModel;
    private javax.swing.JComboBox jCmbProgram;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField jTxtCard;
    private javax.swing.JTextField jTxtFName;
    private javax.swing.JTextField jTxtLName;
    private javax.swing.JTextField jTxtRegNumber;
    private avenue.ModelBoxRenderer modelBoxRenderer1;
    private avenue.ProgramBoxRenderer programBoxRenderer2;
    private java.util.List<model.Program> programList;
    private javax.persistence.Query programQuery;
    private java.util.List<model.VehicleCategory> vehicleCategoryList;
    private javax.persistence.Query vehicleCategoryQuery;
    private java.util.List<model.VehicleModel> vehicleColourList1;
    private javax.persistence.Query vehicleColoursQuery1;
    private java.util.List<model.VehicleModel> vehicleModelList;
    private javax.persistence.Query vehicleModelQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    private javax.persistence.EntityManager avenuePUEntityManager;
    Vehicle vehicle1;
}
